const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app =  express();
 
const users = require('./routes/api/user')

// body-parser 中间件
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); 

// 连接mongodb
const db = require('./config/dbkeys').dbURI;
mongoose.connect(db, { useNewUrlParser:true })
  .then(() => console.log('MongoDB Connected!'))
  .catch(err => console.log(err))


// routes
app.use('/api/users', users);

app.listen(3000, () => {
  console.log('server running in port 3000');
})